ihelpuoo.weboo.runtime.Module = function()
{
	this.name = null;
	this.HTML = null;
	this.actions = ihelpuoo.util.map();
	this.contentChanged = true;
	this.activeAction = null;
	this.detail = null;
}

ihelpuoo.weboo.runtime.Module.prototype
=
{
	setName: function(name)
	{
		this.name = name;
	}

	,
	valueOf: function(ele)
	{
		this.name = ele.getAttribute("name");
	}

	,
	render: function()
	{
		if(null==this.HTML)
			this.HTML = new ihelpuoo.weboo.runtime.ModuleHTML();
		
		this.HTML.setName(this.name);
		var rt = ihelpuoo.weboo.runtime.me();
		if(rt.isActiveModule(this))
			this.HTML.highlight();

		if(this.actions.size()>0 && this.HTML.isOpened())
		{
			if(this.contentChanged)
				this.redrawActions();
			this.contentChanged = false;
		}
		return this.HTML.shell;
	}
	
	,
	redrawActions: function()
	{
		this.HTML.sub.innerHTML = "";
		for(var key in this.actions.data)
		{
			var a = this.actions.get(key);
			this.HTML.sub.appendChild(a.render());
		}
	}
	
	,
	reload: function()
	{
		var rt = ihelpuoo.weboo.runtime.me();
		var xml = ihelpuoo.http.GETXML(ihelpuoo.http.server().url(rt.NAME,rt.URL_GET_ACTIONS,"moduleName="+this.name));
		var children = xml.documentElement.getElementsByTagName("action");
		this.actions.clear();
		this.contentChanged = true;
		for(var i=0;i<children.length;i++)
		{
			var oA = children.item(i);
			var action = new ihelpuoo.weboo.runtime.Action(this);
			action.valueOf(oA);
			this.actions.put(action.name,action);
		}
		
		xml = ihelpuoo.http.GETXML(ihelpuoo.http.server().url(rt.NAME,rt.URL_GET_MODULEDETAIL,"moduleName="+this.name));
		this.detail = new ihelpuoo.weboo.runtime.ModuleDetail(this);
		this.detail.valueOf(xml.documentElement);
	}
	
	,
	getAction: function(name)
	{
		return this.actions.get(name);
	}
	
	,
	hasAction: function(name)
	{
		return this.actions.containsKey(name);
	}
	
	,
	setActiveAction: function(Action)
	{
		var oldActiveAction = null;
		if(null!=this.activeAction && this.activeAction!=Action)
			oldActiveAction = this.activeAction;
		this.activeAction = Action;
		if(null!=oldActiveAction)
		{
			oldActiveAction.disactive();
		}
	}
	
	,
	isActiveAction: function(Action)
	{
		if(null==this.activeAction) return false;
		if(null==Action)return false;
		return this.activeAction==Action;
	}
	
	,
	disactive: function()
	{
		this.disActiveAction();
		this.HTML.dishighlight();
		if(null!=this.detail)
			if(null!=this.detail.HTML)
				this.detail.HTML.hide();
	}
	
	,
	disActiveAction: function()
	{
		if(null==this.activeAction) return;
		var a = this.activeAction;
		this.activeAction = null;
		a.render();
	}
	
	,dump: function()
	{
		return "[Module] " + this.name;
	}
}